#pragma once
#include "BrushLib.h"
#include "PenLib.h"
#include "FontLib.h"
#include <GdiPlus.h>
using namespace Gdiplus;

/// <summary>
/// Inherit from CDC.
/// Use GDI+ object to draw text, line, image.
/// </summary>
/// <remark>
/// The method which named "...Plus" means that use GDI+ object to draw it.
/// This object can manage Font, Pen and Brush by self.
/// </remark>
class AFX_EXT_CLASS CDCPlus : public CDC
{
public:
	CDCPlus(CFontLib* pFontLib, CPenLib* pPens, CBrushLib* pBrushs);
	~CDCPlus(void);

public:

	// style type
	enum STYLE_TYPE
	{
		STYLE_TYPE_DISPLAY,
		STYLE_TYPE_PRINT_HORIZONTAL,
		STYLE_TYPE_PRINT_VERTICAL
	};


protected:
	// Font
	CString		m_strFontFamily;
	float		m_fFontSize;
	FontStyle	m_enFontStyle;

	// Pen
	COLORREF	m_crPen;
	float		m_fPenWidth;
	CPenLib::PEN_PROPERTIES m_sPenProperties;

	// Brush
	COLORREF	m_crBrush;
	CBrushLib::BRUSH_TYPE	m_enBrushType;
	CBrushLib::BRUSH_PROPERTIES	m_sBushProperties;

	// style type
	STYLE_TYPE	m_enStyleType;

	// GDI+ object
	auto_ptr<Graphics>	m_pGraphic;
	CFontLib*	m_pFonts;
	CPenLib*	m_pPens;
	CBrushLib*	m_pBrushs;
	// original point
	Point		m_ptOrignal;

	// Ratio
	float m_fXRatio;
	float m_fYRatio;

public:
	void		SetFontPlus(CString strFontFamily, float fFontSize, FontStyle enFontStyle);
	void		SetPenPlus(COLORREF cr, float fWidth);
	void		SetPenPlus(COLORREF cr, float fWidth, CPenLib::PEN_PROPERTIES &sPenProperties);
	void		SetBrushPlus(COLORREF crBrush, CBrushLib::BRUSH_TYPE enBrushType);
	void		SetBrushPlus(COLORREF crBrush, CBrushLib::BRUSH_TYPE enBrushType, CBrushLib::BRUSH_PROPERTIES &sBushProperties);

	CFontLib*	GetFonts() const { return m_pFonts; }
	CBrushLib*	GetBrushs() const { return m_pBrushs; }
	CPenLib*	GetPens() const { return m_pPens; }

	BOOL		AttachPlus(HDC hDC);
	HDC			DetachPlus();

	Status ArcPlus( LPCRECT lpRect, float startAngle, float sweepAngle );
	Status FillRgnPlus( CRgn* pRgn);
	Status FillRgnPlus(LPPOINT pPoints, int nPointNum, int nMode = WINDING);
	// Drawing-Attribute Functions
	CDCPlus::STYLE_TYPE GetStyleTypePlus() const { return m_enStyleType; }
	void		SetStyleTypePlus(CDCPlus::STYLE_TYPE val) { m_enStyleType = val; }
	void		GetRatioPlus(float& fXRatio,float& fYRatio);
	void		SetRatioPlus(float fXRatio,float fYRatio);

	//	Line-Output
	Status		LineToPlus ( int x, int y );
	Status		LineToPlus ( CPoint point );
	void		MoveToPlus ( int x, int y ); 
	void		MoveToPlus ( CPoint point );
	Status		PolylinePlus ( LPPOINT pPoints, int nCount );
	// Polygon Function
	Status		PolygonPlus ( LPPOINT pPoints, int nCount );
	Status		RectanglePlus ( int x1, int y1, int x2, int y2 );
	Status		RectanglePlus ( LPCRECT lpRect );
	Status		EllipsePlus( LPCRECT lpRect );

	// Text Functions
	Status		DrawTextPlus( const CString& str, LPRECT lpRect, UINT nFormat );
	Status		TextOutPlus ( float x, float y, const CString& str );

	//others
	Status		StretchBltPlus( int x, int y, int nWidth, int nHeight,
		CDC* pSrcDC, int xSrc = 0, int ySrc = 0,
		int nSrcWidth = 0, int nSrcHeight = 0 );
	Status		StretchBltPlus( int x, int y, int nWidth, int nHeight,
		LPCTSTR lpszImagePath, int xSrc = 0, int ySrc = 0,
		int nSrcWidth = 0, int nSrcHeight = 0 );
};
